#include "Tester.h"
#include "MyGame.h"
#include <Support\Config.h>
#include <Support\Log.h>
// #include <Support\GAssert.h>
#include <Support\Storage.h>

#include <Support\String.h>

#ifdef __STRINGTESTER__ON

#include "housekeeping.h"

TEST(String, Constructor)
{
	MyGame game;
	bool result = initGame(game);

	String str0;
	char* ptr = str0.get();
	EXPECT_TRUE(NULL == ptr || nullptr == ptr || strcmp( "", ptr) == 0);	
	 
	String str1("test");
	EXPECT_TRUE(strcmp(str1.get(), "test") == 0);

	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}

TEST(String, Assign)
{
	MyGame game;
	bool result = initGame(game);
	String str1;
	str1 = "test";
	EXPECT_TRUE(strcmp(str1.get(), "test") == 0);

	String str2;
	str2 = str1;
	EXPECT_TRUE(strcmp(str2.get(), "test") == 0);

	String str3 = str1;
	EXPECT_TRUE(strcmp(str3.get(), "test") == 0);

	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}

TEST(String, Get)
{
	MyGame game;
	bool result = initGame(game);

	String str1("Initial");
	EXPECT_TRUE(strcmp(str1.get(), "") != 0);

	str1 = "test";
	EXPECT_TRUE(strcmp(str1.get(), "test") == 0);
	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}

TEST(String, Set)
{
	MyGame game;
	bool result = initGame(game);

	String str1("Initial");
	EXPECT_TRUE(strcmp(str1.get(), "") != 0);

	str1.set("test");
	EXPECT_TRUE(strcmp(str1.get(), "test") == 0);

	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}

TEST(String, Lowercase)
{
	MyGame game;
	bool result = initGame(game);

	String str1("Initial");
	EXPECT_TRUE(strcmp(str1.get(), "") != 0);

	str1.toLowerCase();
	EXPECT_TRUE(strcmp(str1.get(), "initial") == 0);

	str1 = "TEST";
	str1.toLowerCase();
	EXPECT_TRUE(strcmp(str1.get(), "test") == 0);

	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}

TEST(String, Uppercase)
{
	MyGame game;
	bool result = initGame(game);

	String str1("Initial");
	EXPECT_TRUE(strcmp(str1.get(), "") != 0);

	str1.toUpperCase();
	EXPECT_TRUE(strcmp(str1.get(), "INITIAL") == 0);

	str1 = "TEST";
	str1.toUpperCase();
	EXPECT_TRUE(strcmp(str1.get(), "TEST") == 0);

	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}


TEST(String, Trimming)
{
	String str1;

	MyGame game;
	bool result = initGame(game);

	str1 = "   Initial test for trimming   ";
	EXPECT_TRUE(strcmp(str1.get(), "") != 0);

	bool left = true;
	bool right = false;

	str1 = "   Initial test for trimming   ";
	str1.trim(left, right);
	EXPECT_TRUE(strcmp(str1.get(), "Initial test for trimming   ") == 0);
	str1 = "   Initial test for trimming   ";
	str1.trimLeft();
	EXPECT_TRUE(strcmp(str1.get(), "Initial test for trimming   ") == 0);

	left = false;
	right = true;
	str1 = "   Initial test for trimming   ";
	str1.trim(left, right);
	EXPECT_TRUE(strcmp(str1.get(), "   Initial test for trimming") == 0);
	str1 = "   Initial test for trimming   ";
	str1.trimRight();
	EXPECT_TRUE(strcmp(str1.get(), "   Initial test for trimming") == 0);

	str1 = "   Initial test for trimming";
	str1.trim();
	EXPECT_TRUE(strcmp(str1.get(), "Initial test for trimming") == 0);

	EXPECT_TRUE(result);
	if (result)
	{
		ending(&game);
	}
}

#endif